


 
from pydantic import BaseModel,FilePath,Field
from langchain_core.utils.pydantic import (
    PydanticBaseModel,
    TBaseModel,
)

from langchain_core.beta.runnables.context import Context
from langchain_core.runnables.passthrough import RunnablePassthrough
from langchain_core.prompts.prompt import PromptTemplate
from langchain_core.output_parsers.string import StrOutputParser
from langchain.schema import HumanMessage, SystemMessage
 
 
from langchain.chat_models import ChatOpenAI
from langchain.output_parsers import PandasDataFrameOutputParser, OutputFixingParser
from langchain_core.prompts import PromptTemplate
import pandas as pd

from langchain_core.example_selectors import (
    LengthBasedExampleSelector,
    MaxMarginalRelevanceExampleSelector,
    SemanticSimilarityExampleSelector,
)
from langchain_core.prompts import (
    AIMessagePromptTemplate,
    BaseChatPromptTemplate,
    BasePromptTemplate,
    ChatMessagePromptTemplate,
    ChatPromptTemplate,
    FewShotChatMessagePromptTemplate,
    FewShotPromptTemplate,
    FewShotPromptWithTemplates,
    HumanMessagePromptTemplate,
    MessagesPlaceholder,
    PipelinePromptTemplate,
    PromptTemplate,
    StringPromptTemplate,
    SystemMessagePromptTemplate,
    load_prompt,
)

from langchain._api import create_importer
from langchain.prompts.prompt import Prompt

llm = ChatOpenAI(
    model="deepseek-chat",
    temperature=0,
    openai_api_key="sk-605e60a1301040759a821b6b677556fb",
    base_url="https://api.deepseek.com/v1")

from langchain.tools import StructuredTool
from pydantic import BaseModel

class FileInput(BaseModel):
    path: str
    encoding: str = "utf-8"

def read_file(path: str, encoding: str) -> str:
    with open(path, encoding=encoding) as f:
        return f.read()

file_tool = StructuredTool.from_function(
    func=read_file,
    name="file_reader",
    description="读取文本文件内容",
    args_schema=FileInput,
    return_direct=True
)
from langchain_core.tools import tool

@tool
def multiply(a: int, b: int) -> int:
    """输入两个整数返回乘积结果"""
    return a * b

print(multiply.name)  # 输出工具名称
print(multiply.args)  # 输出参数结构


from langchain.agents import AgentExecutor, create_react_agent
from langchain.tools import Tool
from langchain_community.utilities import GoogleSearchAPIWrapper
 
agent = create_react_agent(llm=llm, tools=[multiply])
executor = AgentExecutor(agent=agent, tools=[tool])
print(executor.run("1*2?"))
